import unittest
import pandas as pd
from dev.stock_information.fund_detail import get_fund, fund_stock_holding,fund_self_compare

class FundDetailTest(unittest.TestCase):

    def test_get_fund(self):
        print("************   测试fund_detail.get_fund()   ************")
        symbol = "005827"
        years = ['2019', '2020', '2021','2022']
        data = get_fund(symbol=symbol,years=years)
        print(data)

    def test_fund_stock_holding(self):
        print("************   测试fund_detail.fund_stock_holding()   ************")
        years = ['2020', '2021']
        df3 = fund_stock_holding(symbol='005827',years=years)
        print(df3)

        codes = ['005669', '006281', '003956', '001532',
                 '001714', '001054', '001809', '003853',
                 '004890', '001125', '001808']
        df = pd.DataFrame()
        for code in codes:
            df_tmp = fund_stock_holding(symbol=code,years=years)
            df = df.append(df_tmp)
        print(df)

    def test_fund_self_compare(self):
        print("************   测试fund_detail.fund_self_compare()   ************")
        # 易方达蓝筹精选，005827
        # 前海开源公共事业股票，005669
        symbol = "005827"
        years = ['2019', '2020', '2021', '2022']
        # 假设咱们需要对比2022年1季度和2022年2季度的持仓变化情况，则只需要在上面的数据上选择 2021Q1 和 2021Q2 即可。
        s1 = '2022Q1'
        s2 = '2022Q2'

        df_merge = fund_self_compare(symbol=symbol, years=years, s1=s1, s2=s2)
        print(df_merge)  # 可以看到，2022的Q2季度对海康威视和平安银行的股票进行清仓处理